#include <gst/gst.h>

static GMainLoop *loop = NULL;

static gboolean my_bus_callback( GstBus *bus, GstMessage *msg, gpointer data )
{
    g_print( "Got %s message\n", GST_MESSAGE_TYPE_NAME(message) );
    switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_ERROR: {
        GError *err = NULL;
        gchar *debug = NULL;

        gst_message_parse_error (message, &err, &debug);
        g_print ("Error: %s\n", err->message);
        g_error_free (err);

        g_main_loop_quit(loop);
        break;
    }
    case GST_MESSAGE_EOS:
        /* end of stream */
        g_main_loop_quit (loop);
        break;
    default:
        break;
    }
}

int main(int argc, char *argv[])
{
    GstElement *pipeline = NULL;
    GstBus *bus = NULL;
    guint busWatchID;

    gst_init(&argc, &argv);

    pipeline = gst_pipeline_new("My-Pipeline");
    if (!pipeline) {
        g_warning("Create pipeline failed");
        return -1;
    }

    bus = gst_pipeline_get_bus (GST_PIPELINE(pipeline));
    busWatchID = gst_bus_add_watch (bus, my_bus_callback, NULL);
    gst_object_unref (bus);

    /* doing something */

    return 0;
}

